import 'package:flutter/material.dart';

import '../util.dart';
import 'ifly_dialog.dart';
import 'model.dart';
import 'xf_api_utils.dart';

class IFlyUtil {
  static final IFlyUtil instance = IFlyUtil._interval();
  factory IFlyUtil() => instance;
  IFlyUtil._interval();
  final man = XFApiUtils();

  // ignore: non_constant_identifier_names
  Future<RecordResult> ifly_audio() async {
    // record.dec();

    RecordResult? result = await Get.bottomSheet(
      IflyDialog(
        man: man,
      ),
      isScrollControlled: false,
      isDismissible: false,
      enableDrag: true,
    );
    if (result == null) {
      await man.cancel();
      var res = RecordResult.cancel();
      Get.log('录音取消===${res.json}');
      Hud.toast('录音取消');
      return res;
    }
    if (result.status == -1) {
      await man.stop();

      var res = RecordResult.success(
        transform: man.recordString,
      );
      Get.log('录音完成---${res.json}');

      return res;
    }

    return result;
  }
}
